//
//  EnrollDetailViewController.swift
//  DriverSchoolAPP
//
//  Created by Logel on 2017/5/18.
//  Copyright © 2017年 Logel. All rights reserved.
//

import UIKit

class EnrollDetailViewController: UIViewController,UITextFieldDelegate {
    @IBOutlet weak var nameLbl: UITextField!
    var sex = "man"
    @IBOutlet weak var idCardNumberLbl: UITextField!
    @IBOutlet weak var phoneLbl: UITextField!
    @IBOutlet weak var addressLbl: UITextField!
    @IBOutlet weak var consessionsCodeLbl: UITextField!
    var orderType = "1"
    @IBOutlet weak var img_Man: UIImageView!
    @IBOutlet weak var img_Woman: UIImageView!
    @IBOutlet weak var img1: UIImageView!
    @IBOutlet weak var img2: UIImageView!
    @IBOutlet weak var img3: UIImageView!
    @IBOutlet weak var img4: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
    @IBAction func backEnroll(_ sender: UIButton) {
        
        if oList.count < 4 {
            if (nameLbl.text! != "" && phoneLbl.text! != "" && idCardNumberLbl.text! != "" && addressLbl.text! != "") {
                var o = Order()
                o.orderType = orderType
                o.name = nameLbl.text!
                o.mobile = phoneLbl.text!
                o.idCardNumber = idCardNumberLbl.text!
                o.gender = sex
                o.address = addressLbl.text!
                o.consessionsCode = consessionsCodeLbl.text!
                oList.append(o)
                self.navigationController?.popViewController(animated: true)
            }else{
                showMsg(msg: "必填信息不完全")
            }

        }else{
            showMsg(msg: "一次最多能报名四人！")
        }
        
    }
    @IBAction func selectMan(_ sender: UIButton) {
        sex = "man"
        img_Man.image = UIImage(named: "selected")
        img_Woman.image = UIImage(named: "select")
    }

    @IBAction func selectweman(_ sender: UIButton) {
        sex = "woman"
        img_Man.image = UIImage(named: "select")
        img_Woman.image = UIImage(named: "selected")
    }
    @IBAction func doSelectType(_ sender: UIButton) {
        orderType = String(sender.tag)
        switch sender.tag {
        case 1:
            img1.image = UIImage(named: "selected")
            img2.image = UIImage(named: "select")
            img3.image = UIImage(named: "select")
            img4.image = UIImage(named: "select")
        case 2:
            img1.image = UIImage(named: "select")
            img2.image = UIImage(named: "select")
            img3.image = UIImage(named: "selected")
            img4.image = UIImage(named: "select")
        case 3:
            img1.image = UIImage(named: "select")
            img2.image = UIImage(named: "selected")
            img3.image = UIImage(named: "select")
            img4.image = UIImage(named: "select")
            
        case 4:
            img1.image = UIImage(named: "select")
            img2.image = UIImage(named: "select")
            img3.image = UIImage(named: "select")
            img4.image = UIImage(named: "selected")
        default:
            break
        }
    }
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        nameLbl.resignFirstResponder()
        idCardNumberLbl.resignFirstResponder()
        addressLbl.resignFirstResponder()
        phoneLbl.resignFirstResponder()
        consessionsCodeLbl.resignFirstResponder()
    }
}
